package com.mayikt;

import sun.awt.datatransfer.ToolkitThreadBlockedHandler;

import java.util.concurrent.BlockingDeque;
import java.util.concurrent.CountDownLatch;

/**
 * @ClassName Test33
 * @Author 蚂蚁课堂余胜军 QQ644064779 www.mayikt.com
 * @Version V1.0
 **/
public class Test33 {
    public static void main(String[] args) {
        CountDownLatch countDownLatch = new CountDownLatch(2);// 计数器 基于aqs state 2
        for (int i = 1; i <= 3; i++) {
            int finalI = i;
            new Thread(() -> {
                System.out.println("线程名称:" + finalI + "，阻塞呢");
                try {
                    countDownLatch.await();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("线程名称:" + finalI + "，唤醒呢");
            }, "线程名称:" + i).start();
        }
        countDownLatch.countDown();//aqs 状态-1  // 2-1 =1
        countDownLatch.countDown();
        //只有当我们aqs 状态为0的情况下才会唤醒所有的线程
        // 释放锁 -1
//        new BlockingDeque<>()\
        //线程池底层原理
        //
    }
}
